package com.example.button_app;

import java.io.IOException;
import java.util.logging.Handler;

import android.content.Context;
import android.hardware.usb.UsbManager;
import android.os.Message;
import android.util.Log;

import com.hoho.android.usbserial.driver.UsbSerialDriver;
import com.hoho.android.usbserial.driver.UsbSerialProber;




public class TXuart{

public void sendUART(String data)
	{
		manager = (UsbManager) getSystemService(Context.USB_SERVICE);
		// Find the first available driver.
		UsbSerialDriver driver = UsbSerialProber.acquire(manager);
		if (driver != null) {
			  try {
				driver.open();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			  
			  try {
				    driver.setBaudRate(115200);
				    
				    byte buffer[] = new byte[16];
				    int numBytesRead = driver.read(buffer, 1000);
				    Log.d(TAG, "Read " + numBytesRead + " bytes.");
				   
				    
				    byte temp[] = data.getBytes();
				    Message msg = new Message(); 
	    			msg.obj = "\nTransmitted:\n " + data + "\n"; 
	    			Handler.sendMessage(msg);
				    driver.write(temp, 16);
				    
				  } catch (IOException e) {
				    // Deal with error.
				  } finally {
				    try {
						driver.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						
						e.printStackTrace();
					}
				  } 
				

			  
		}
			 

		
	}}